import { magnetDecode } from '@ctrl/magnet-link';
import fs from 'fs';
import { info, files, decode } from '@ctrl/torrent-file';



function decodeMaget() {
    const uri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.example4.com%3A80&tr=udp%3A%2F%2Ftracker.example5.com%3A80&tr=udp%3A%2F%2Ftracker.example3.com%3A6969&tr=udp%3A%2F%2Ftracker.example2.com%3A80&tr=udp%3A%2F%2Ftracker.example1.com%3A1337';
    const parsed = magnetDecode(uri);
    console.log(parsed.dn) // "Leaves of Grass by Walt Whitman.epub"
    console.log(parsed.infoHash) // "d2474e86c95b19b8bcfdb92bc12c9d44667cfa36"
}

function parseTorrentFile() {
    const torrentInfo = files(fs.readFileSync('/Users/shanke/Downloads/[BTSCHOOL].[狙击手白乌鸦]Sniper.The.White.Raven.2022.BluRay.720p.x264.2Audios.AC3-BtsHD.mkv.torrent'));
    console.log(torrentInfo.files);
}

;(() => {
    // decodeMaget();
    parseTorrentFile();
}
)()
